package com.hyts.bmsp.plugin;

import java.io.IOException;
import java.util.Properties;

import com.hyts.bmsp.error.ProcessError;
import org.apache.log4j.Logger;

import com.jfinal.config.Plugins;
import com.jfinal.plugin.c3p0.C3p0Plugin;

/**
 * @ClassName: C3p0SupportPlugin
 * @Description: c3p0 数据源插件
 * @author: 李博/Alex
 * @date: 2017-1-7 下午11:59:45
 */
@SuppressWarnings("unused")
public class C3p0SupportPlugin {

	/**
	 * @fieldName: JDBC_PROPERTIES_FILE_PATH
	 * @fieldType: String
	 * @Description: 系统jdbc数据库连接池参数配置信息
	 */
	private static final String JDBC_PROPERTIES_FILE_PATH = "jdbc.properties";
	
	/**
	 * @fieldName: logger
	 * @fieldType: Logger
	 * @Description: Logger日志输出器
	 */
	private static final Logger logger = Logger.getLogger(C3p0SupportPlugin.class);
	
	/**
	 * @fieldName: c3p0Plugin
	 * @fieldType: C3p0Plugin
	 * @Description: 创建C3p0数据库连接池
	 */
	private C3p0Plugin c3p0Plugin;
	
	/**
	 * @Title:C3p0SupportPlugin
	 * @Description:构造系统C3P0插件
	 * @param me
	 */
	public C3p0SupportPlugin(Plugins me){
		if(me == null)
			throw new ProcessError("程序启动加载数据源C3P0插件是出现错误：基础C3P0插件为空!");
		Properties jdbcProperties = new Properties();
		try {
			logger.info("启动C3p0插件操作信息......");
			jdbcProperties.load(C3p0SupportPlugin.class.getClassLoader().getResourceAsStream(JDBC_PROPERTIES_FILE_PATH));
		} catch (IOException e) {
			e.printStackTrace();
			logger.error(e);
		}
		c3p0Plugin = new C3p0Plugin(jdbcProperties);
		me.add(c3p0Plugin);
	}

	public C3p0Plugin getC3p0Plugin() {
		return c3p0Plugin;
	}
	
}
